--
-- Author: shunguo.chen
-- Date: 2018-03-19 14:49:29
--
-- ChessEventView	谜棋事件选择
--

local ChessSelectEventRender = import(".renders.ChessSelectEventRender")

local fileName = string.getModeName(...)
local ClassRef = class(fileName, app.mvc.ViewBase)

ClassRef.VIEW_ROOT_RES = Res.ChessEventScene

local REMAIN_TIME_STR = L("left_time_sec")

function ClassRef:init()
	local renders = {0,0,0}
	for i=1,3 do
		local node = self._ui["Panel_" .. i]
		local render = ChessSelectEventRender.create(node)
		render:onBtnClick(handler(self, self._onClickRender))
		renders[i] = render
	end
	self._renders = renders
end

-- data = ChessSelect
-- info = ChessInfo
function ClassRef:refresh(data, info)
	self._data = data
	self._info = info

	local infos = data.infos
	for i,render in ipairs(self._renders) do
		render:setData(infos[i])
	end

	self:_refreshTime()
end

function ClassRef:_onClickRender(render)
	local info = render:getData()
	executeFunc(self._onOperate, "selectEvent", info.selectID)
	executeFunc(self._onCloseView, self)
end

function ClassRef:_refreshTime()
	local remainTime = self._info:getRemainTime()
	if remainTime <= 0 then
		display.pushToast(L("lua_code_text_475"))
		executeFunc(self._onCloseView, self)
		return
	end

	self._ui.tips:setString(string.format(L(REMAIN_TIME_STR), remainTime))
	self._ui.tips:performWithDelay(function()
			self:_refreshTime()
		end, 1)
end

return ClassRef
